package cn.inyaa.admin.sys.controller;

import cn.inyaa.admin.sys.bean.InyaaSysUser;
import cn.inyaa.admin.sys.service.InyaaSysUserService;
import cn.inyaa.admin.sys.vo.InyaaSysUserVo;
import com.inyaa.base.bean.BaseResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class InyaaSysUserController {

    private final InyaaSysUserService inyaaSysUserService;

    @GetMapping("/info")
    public BaseResult<Object> info(Principal principal) {
        InyaaSysUser user = inyaaSysUserService.getByUsername(principal.getName());
        return BaseResult.success(user);
    }

    @GetMapping("/list")
    public BaseResult<List<InyaaSysUserVo>> list(InyaaSysUser user) {
        return BaseResult.success(inyaaSysUserService.findUserList());
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public BaseResult<String> save(@RequestBody InyaaSysUser user) {
        inyaaSysUserService.save(user);
        return BaseResult.success();
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public BaseResult<String> delete(@RequestBody InyaaSysUser user) {
        inyaaSysUserService.delete(user);
        return BaseResult.success();
    }
}
